from flask import Flask, render_template
from flask_socketio import SocketIO, send

app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret!'
socketio = SocketIO(app)

@app.route('/')
def index():
    return render_template('index.html')

@app.route("/wegame")
def wegame():
    return render_template('wegame.html')

@socketio.on('message')
def handle_message(message):
    nickname = message['nickname']
    text = message['text']
    print('Message from ' + nickname + ': ' + text)
    send({'nickname': nickname, 'text': text}, broadcast=True)

if __name__ == '__main__':
    # socketio.run(app, debug=True)
    # 关闭调试模式，并允许外部访问
    socketio.run(app, debug=False, host='0.0.0.0')
